<!doctype html>
<html lang="zh-CN">
<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<title>钢链网-发布资源单</title>
	<link rel="stylesheet" href="/resource/css/gl_index.css">
	<link rel="stylesheet" href="/resource/css/gl_user.css">

	<script src="/resource/js/jquery-1.11.3.min.js"></script>
	<script src="/resource/js/gl_index.js"></script>
    <script src="/resource/js/ajaxfileupload.js"></script>

	<script>
		$(function(){
			var popup_file = '<div class="popup"></div><div class="popup-show popup-file">';
		        popup_file += '<div class=\"popup-p\">';
		        popup_file +='<i><img src=\"/resource/img/gl_show_succ.png\" alt=""></i>';
		        popup_file +='<div class=\"left\">';           
		        popup_file +='<span style="font-size:18px;">已上传成功，请等待审核</span>';                 
		        popup_file +='<div class="btn"><a href="/user_now_resource_admin" class="deter">立即查看</a>';
		        popup_file +='<a href="javascript:;" class="continue">继续上传</a></div>';                 
		        popup_file +='</div></div></div>'; 
		    $('body').append(popup_file); 
		    $('.popup-show').css('margin-left',-$('.popup-show').width()/2);
		    //确认上传
		    $('.resource .form-control').after('<span></span>');
		    $('.resource .form-control').blur(function(){
		    	if(!$(this).val()){
		    		$(this).siblings('span').show().html('不能为空');
		    	}else{
		    		$(this).siblings('span').hide();
		    	}
		    });

		    $(document).delegate('.btn-file','click',function(){
		    	var user_id = $(this).attr('user_id');
		    	var res_input = [];
		    	var check_val = [];

		    	if(!$('#file_ex').val()){
		    		$('#file_ex').parents('.file-ex').siblings('span').show().html('请上传文件');
		    		return false;
		    	}
                if(!$('.category input').val()){
                    $('.category').siblings('span').show().html('不能为空');
                    return false;
                }else{
                    $('.category').siblings('span').hide();
                }
		    	for (var i = 0; i < $('.resource input.form-control').length; i++) {
		    		if(!$('.resource input.form-control').eq(i).val()){
		    			$('.resource input.form-control').eq(i).focus().siblings('span').show().html('不能为空');
		    			return false;
		    		}else{
		    			res_input.push($('.resource input.form-control').eq(i).val());
		    		}
		    	};
	    		if($('.check-box input:checked').length>0){
	    			$('.check-box').siblings('span').hide();
	    			for (var i = 0; i < $('.check-box input:checked').length; i++) {
	    				check_val.push($('.check-box input:checked').eq(i).val());
	    			};	
	    		}else{
	    			$('.check-box').siblings('span').show().html('不能为空');
	    			return false;
	    		};

                $.ajaxFileUpload
                (
                        {
                            url:'/add_excel', //你处理上传文件的服务端
                            secureuri:false,
                            fileElementId:'file_ex',
                            dataType: 'JSON',
                            type:'post',
                            success: function (data)
                            {
                               if(data){
                                   $.ajax({
                                       url: "/user_add_now_resource",
                                       type: "post",
                                       data: 'city=' + res_input[0]+"&factory="+res_input[1]+"&content="+res_input[2]+"&classes="+check_val+"&down_address="+data,
                                       async: false,
                                       success: function (msg) {
                                         if(msg==1){
                                             $('.popup-file .deter').attr('user_id',user_id);
                                             $('.popup-file').show();
                                             $('.popup').show();
                                         }
                                       }
                                   })
                               }
                            }
                        }
                )


		    });
		    $(document).delegate('.popup-file .deter','click',function(){
		    	window.location.href = 'http://www.baidu.com';
		    });
		    $(document).delegate('.popup-file .continue','click',function(){
		    	location=location;
		    });
		    $(document).delegate('.popup','click',function(){
		    	$('.popup-file').show();
		    	$('.popup').show();
		    });
            var str = "";
            $.ajax({
                url:'/ajax_place',
                type:'post',
                data:'',
                success:function(data){console.log(data);

                    $.each(data,function(index,arr){
                            str += "<li rel="+ arr.city_name+">"+arr.city_name+"</li>";
                        $('[name="place"]').parents('.form-group').find('ul').html(str);
                    });
                }
            });


            $('.category').click(function(e){
                var category = $(this);
                e?e.stopPropagation():event.cancelBubble = true;
                if(category.hasClass('open')){
                    category.removeClass('open').siblings('.category-cont').hide();
                }else{
                    $('.category-cont').hide();
                    $('.category').removeClass('open');
                    category.addClass('open').siblings('.category-cont').show();
                }
            });

            $('.category-cont').delegate('li','click',function(){
                var name = $(this).html();
                var i_d = $(this).attr('rel');
                $(this).parents('.form-group').find('.category-title').html(name);
                $(this).parents('.form-group').find('input').val(i_d);
                $('.category-cont').hide();
                $('.category').removeClass('open');
            });

            $('.category-cont').click(function(e){
                e?e.stopPropagation():event.cancelBubble = true;
            });

            $(document).click(function(){
                $('.category-cont').hide();
                $('.category').removeClass('open');
            });

		});
	</script>
</head>
<body>
<div class="head">
    @include('common.user_head')
</div>
<div class="user-head">
	<div class="main">
		<div class="logo">
			<a href="/"><img src="/resource/img/logo.png" alt=""></a>
			<div>我的钢链网
				<a href="/">返回首页</a>
			</div>
		</div>
	</div>
</div>	
<div class="user main">
    @include('common.user_menu')
	<div class="user-cont">
		<div class="resource">
			<div class="title">发布资源单</div>
			<div class="prompt">温馨提示：发布成功后，1个工作日内审核完成</div>
			{{--<div class="seller-no-">您还未完成企业认证，无法交易，请<a href="javascript:;">立即认证</a></div>--}}
			<div class="form">
				<form action="">   
					<div class="form-group">
						<label for="">上传资源单：</label>
						<div class="file-ex">
							<label for="file_ex">选择文档</label>
							<input type="file" id="file_ex" name="file_ex">
						</div>
						<div class="info">
							上传excel表格文件<br/>
							<i>(支持xls、xlsx格式，文件大小不超过3M)</i>
							<a href="/down_excel?filename=resource/ganglianw.xls&old_name={{$old_name}}">下载资源单模板</a>
						</div>
						<span></span>
					</div>
					<div class="form-group">
						<label for="">公司抬头：</label>
						<div style="line-height:36px;">{{$company}}</div>
					</div>
                    <div class="form-group over-auto">
                        <label for="">地区：</label>
                        <div class="form-control category">
                            <div class="category-title">
                                全部
                            </div>
                            <i></i>
                            <input type="hidden" name="place" value="">
                        </div>
                        <div class="category-cont"><ul></ul></div>
                        <div class="clear"></div>
                    </div>
					<div class="form-group">
						<label for="">主营钢厂：</label>
						<input type="text" class="form-control" name="factory">
					</div>
                    <div class="form-group">
                        <label for="">资源单描述：</label>
                        <textarea name="content" id="" class="form-control form-text"></textarea>
                    </div>
					<div class="form-group last">
						<label for="">品类：</label>
                        @for($i=0;$i<count($category);$i++)
						<div class="check-box"><input type="checkbox" value="{{$category[$i]->category_name}}" id="cart_{{$i}}"><label for="cart_{{$i}}">{{$category[$i]->category_name}}</label></div>
                        @endfor
                            <div class="in">可多选</div>
						<span></span>
					</div>
					<input type="button" class="btn-file" value="确认上传">
				</form>
			</div>
		</div>
	</div>
</div>
@include('common.shop_foot')
</body>
</html>